package com.zsrt.java.day20161223.wrl.homework;

import java.util.Scanner;
import org.junit.Test;

public class Work06 {
	
	/**
	 * 用switch完成：加减乘除求模的计算器，同时用if else 也要写一遍
	 */
	@Test
	public void w06Switch(){
		System.out.println("请输入第一个数：\n");
		Scanner sc = new Scanner(System.in);
		int index1 = sc.nextInt();
		System.out.println("请输入运算符：+  -  *  /  %\n");
		String index2 = sc.next();
		System.out.println("请输入第二个数：\n");
		int index3 = sc.nextInt();
		sc.close();
		switch (index2) {
			case "+":	System.out.println(index1+index3);		break;
			case "-":	System.out.println(index1-index3);		break;
			case "*":	System.out.println(index1*index3);		break;
			case "/":	System.out.println(index1/index3);		break;
			case "%":	System.out.println(index1%index3);		break;
			default:	System.out.println("您的输入有误！");		break;
		}
	}
	@Test
	public void w06IfElse(){
		System.out.println("请输入第一个数：");
		Scanner sc = new Scanner(System.in);
		int index1 = sc.nextInt();
		System.out.println("请输入运算符：+  -  *  /  %");
		String index2 = sc.next();
		System.out.println("请输入第二个数：");
		int index3 = sc.nextInt();
		sc.close();
		if("+".equals(index2)){
			System.out.println(index1 + index3);
		}else if("-".equals(index2)){
			System.out.println(index1 - index3);
		}else if("*".equals(index2)){
			System.out.println(index1 * index3);
		}else if("/".equals(index2)){
			System.out.println(index1 / index3);
		}else if("%".equals(index2)){
			System.out.println(index1 % index3);
		}else{	
			System.out.println("您的输入有误！");		
		}
	}
}
